package main

import (
	. "GO_data_structures_and_algorithms/tool"
	"fmt"
)

func main() {
	_, ints := LenRandomValueRandom(10, 15)

	fmt.Println(ints)
	InsertSort2(ints)
	fmt.Println(ints)
	//fmt.Println(findMostLeftLessNumIndex(ints, 10))
	fmt.Println(findMostRrightBigNumIndex(ints, 10))
}

func findByTwo(arr []int, num int) (bool, int) {

	if arr == nil || len(arr) == 0 {
		return false, 0
	}
	L := 0
	R := len(arr) - 1

	for R > L {

		mid := (L + R) / 2
		if num == arr[mid] {
			return true, mid
		} else if arr[mid] > num {
			R = mid - 1
		} else {
			L = mid + 1
		}
	}
	return false, 0
}
func findMostLeftLessNumIndex(arr []int, num int) int {
	if arr == nil {
		return -1
	}
	index := -1
	L := 0
	R := len(arr) - 1
	for R >= L {
		mid := (L + R) / 2
		if arr[mid] >= num {
			index = mid
			R = mid - 1
		} else {
			L = mid + 1
		}
	}
	return index
}
func findMostRrightBigNumIndex(arr []int, num int) int {
	if arr == nil {
		return -1
	}
	index := -1
	L := 0
	R := len(arr) - 1
	for R >= L {
		mid := (L + R) / 2
		if arr[mid] >= num {

			R = mid - 1
		} else {
			index = mid
			L = mid + 1
		}
	}
	return index
}
